package cn.source.system.controller.api;

import cn.source.common.core.domain.AjaxResult;
import cn.source.system.controller.api.response.ApiCategoryResponse;
import cn.source.system.domain.AaCategory;
import cn.source.system.service.IAaBannerService;
import cn.source.system.service.IAaCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chensl
 * @version 1.0.0
 * @ClassName ApiBannerController.java
 * @Description
 * @createTime 2023/8/5 19:40
 */
@RestController
@RequestMapping("/api/category")
public class ApiCategoryController {

    @Autowired
    private IAaCategoryService aaCategoryService;

    /**
     * 根据一级分类ID获取二级分类
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(Long id)
    {
        List<AaCategory> list = aaCategoryService.selectAaCategoryByPid(id);
        List<ApiCategoryResponse> responseList = list.stream().map(m->{
            ApiCategoryResponse response = new ApiCategoryResponse();
            response.setId(m.getId());
            response.setName(m.getCategoryName());
            return response;
        }).collect(Collectors.toList());
        return AjaxResult.success(responseList);
    }

}
